package com.cloud.adrian.novel.news.controller;

import com.cloud.adrian.novel.common.constant.ApiRouterConstants;
import com.cloud.adrian.novel.common.resp.RestResp;
import com.cloud.adrian.novel.news.dto.resp.NewsInfoRespDto;
import com.cloud.adrian.novel.news.service.NewsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 前台门户-新闻模块 api控制器
 * @Author: xiangguiliang
 * @version: 1.0
 * @since: 2024/05/21
 */
@Tag(name = "NewsController", description = "前台门户-新闻模块")
@RestController
@RequestMapping(ApiRouterConstants.API_FRONT_NEWS_URL_PREFIX)
@RequiredArgsConstructor
public class NewsController {
    private final NewsService newsService;

    /**
     * 查询最新新闻列表
     */
    @Operation(summary = "查询最新新闻列表")
    @GetMapping("latest_list")
    public RestResp<List<NewsInfoRespDto>> listLatestNews() {
        return newsService.listLatestNews();
    }

    /**
     * 查询新闻详情
     */
    @Operation(description = "查询新闻详情")
    @GetMapping("{id}")
    public RestResp<NewsInfoRespDto> getNews(
            @Parameter(description = "新闻ID") @PathVariable("id") Long id) {
        return newsService.getNews(id);
    }
}
